package io.github.truenine.composeserver.depend.jackson

import com.fasterxml.jackson.databind.ObjectMapper
import io.github.truenine.composeserver.datetime
import io.github.truenine.composeserver.depend.jackson.modules.DatetimeCustomModule
import io.github.truenine.composeserver.testtoolkit.log
import jakarta.annotation.Resource
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class DatetimeSerializerTest {
  lateinit var mapper: ObjectMapper
    @Resource set

  @BeforeEach
  fun setup() {
    // 使用时间戳序列化模块，确保时区无关性
    mapper.registerModule(DatetimeCustomModule())
  }

  @Test
  @Disabled("因为时区差异暂时禁用此测试")
  fun `ensure serialize to number`() {
    val dt = datetime.now()
    val dtJson = mapper.writeValueAsString(dt)
    log.info("dtJson: {}", dtJson)
    assertNotNull(dtJson.toLongOrNull())
    val dt2 = mapper.readValue(dtJson, datetime::class.java)
    assertNotNull(dt2)
    assertEquals(dt.year, dt2.year)
    assertEquals(dt.month, dt2.month)
    assertEquals(dt.dayOfMonth, dt2.dayOfMonth)
    assertEquals(dt.hour, dt2.hour)
    assertEquals(dt.minute, dt2.minute)
    assertEquals(dt.second, dt2.second)
  }
}
